<?php
/**
 * Created by PhpStorm.
 * User: yuanluke
 * Date: 5/1/16
 * Time: 07:08
 */

namespace App\Http\Utils\Common;


class SmsUtils
{

    function SudasSmsPost($url, $request)
    {
        $output = true;

        $show_header = false;

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);    //发送的数据

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, $output); //设定返回的数据是否自动显示

        curl_setopt($ch, CURLOPT_HEADER, $show_header);    //设定是否显示头信息

        $ReturnData = curl_exec($ch);

        curl_close($ch);

        return $ReturnData;
    }

    public function sendSms($phone,$num)
    {
        $sn = "SUD-KEY-010-00348";

        $pwd = "A276C7BE7DE6F4A7ED2CB768D9E7FE93";

        $mobile = $phone;

        $content = '您好。您的验证码为'.$num.'。请及时操作！【七彩365】';

        $ext = '';

        $rrid = '';

        $stime = '';

        $stype = 1;

        $ssafe = 1;

        $scode = 1;                //1表示UTF-8，2表示GB2312

        $MARK = "|";

        $Md5key = "wonieg";

        $Md5Sign = md5($sn . $MARK . $pwd . $MARK . $mobile . $MARK . $content . $MARK . $ext . $MARK . $rrid . $MARK . $stime . $MARK . $stype . $MARK . $ssafe . $MARK . $scode . $MARK . $Md5key);

//        $target = "http://sdk.sudas.cn";
        $target = "http://sdk8.interface.sudas.cn/z_mdsmssend.php";

        $subdate = "sn=" . $sn . "&pwd=" . $pwd . "&Md5Sign=" . $Md5Sign . "&mobile=" . $mobile . "&content=" . urlencode($content) . "&ext=" . $ext . "&stime=" . $stime . "&rrid=" . $rrid . "&stype=" . $stype . "&ssafe=" . $ssafe . "&scode=" . $scode;

        $sendMsgID = $this->SudasSmsPost($target, $subdate);

        if ($sendMsgID > 1) {
            return true;
        } else {
            return false;
        }

    }
}